Skip to content

SONARPHP-1817 fix: resolve 5 SonarQube issues in test files#1699

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260515-050317-e3d294e7
Open

SONARPHP-1817 fix: resolve 5 SonarQube issues in test files#1699
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260515-050317-e3d294e7

Conversation

@sonarqube-agent
Copy link
Copy Markdown
Contributor

Removed unnecessary 'throws Exception' declaration from a test method and removed 'public' modifiers from four JUnit5 lifecycle methods. These changes follow JUnit5 conventions which do not require public visibility and improve code clarity by ensuring method signatures accurately reflect their actual behavior.

View Project in SonarCloud


Fixed Issues

java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINORView issue

Location: php:php-checks/src/test/java/org/sonar/php/checks/phpini/FileUploadsCheckTest.java:33

Why is this an issue?

Superfluous exceptions within throws clauses have negative effects on the readability and maintainability of the code. An exception in a throws clause is superfluous if it is:

What changed

Removes the superfluous 'throws Exception' declaration from the 'lineIssues()' method signature. The method body does not actually throw any checked exception of type 'java.lang.Exception', so declaring it in the throws clause was unnecessary and reduced code readability. By removing it, the method signature now accurately reflects the exceptions that can be thrown.

--- a/php-checks/src/test/java/org/sonar/php/checks/phpini/FileUploadsCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/phpini/FileUploadsCheckTest.java
@@ -33,1 +33,1 @@ class FileUploadsCheckTest {
-  void lineIssues() throws Exception {
+  void lineIssues() {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: php:sonar-php-plugin/src/test/java/org/sonar/plugins/php/SymbolScannerTest.java:58

Why is this an issue?

JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be public. Test classes and methods can have any visibility except private. It is however recommended to use the default package visibility to improve readability.

What changed

This hunk removes the 'public' modifier from the 'init()' lifecycle method in the JUnit5 test class 'SymbolScannerTest'. JUnit5 test classes and methods should use default package visibility rather than 'public', as JUnit5 does not require public visibility. Changing 'public void init()' to 'void init()' follows the JUnit5 convention and resolves the code smell about unnecessary 'public' modifiers on test lifecycle methods.

--- a/sonar-php-plugin/src/test/java/org/sonar/plugins/php/SymbolScannerTest.java
+++ b/sonar-php-plugin/src/test/java/org/sonar/plugins/php/SymbolScannerTest.java
@@ -58,1 +58,1 @@ class SymbolScannerTest {
-  public void init() throws IOException {
+  void init() throws IOException {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: php:sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/phpunit/TestFileReportTest.java:49

Why is this an issue?

JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be public. Test classes and methods can have any visibility except private. It is however recommended to use the default package visibility to improve readability.

What changed

This hunk removes the 'public' modifier from the setUp() lifecycle method in the JUnit5 test class TestFileReportTest, changing it from 'public void setUp()' to 'void setUp()'. JUnit5 test classes and lifecycle methods should use default package visibility rather than 'public', as recommended by the JUnit5 User Guide. This directly addresses the code smell about unnecessary 'public' modifiers on JUnit5 lifecycle methods.

--- a/sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/phpunit/TestFileReportTest.java
+++ b/sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/phpunit/TestFileReportTest.java
@@ -49,1 +49,1 @@ class TestFileReportTest {
-  public void setUp() {
+  void setUp() {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: php:sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/ExternalReportFileHandlerTest.java:39

Why is this an issue?

JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be public. Test classes and methods can have any visibility except private. It is however recommended to use the default package visibility to improve readability.

What changed

This hunk removes the 'public' modifier from the 'setup()' lifecycle method in the JUnit5 test class 'ExternalReportFileHandlerTest'. JUnit5 test classes and methods should use default package visibility rather than 'public', as JUnit5 does not require public visibility. Changing 'public void setup()' to 'void setup()' follows the JUnit5 convention and resolves the code smell about unnecessary 'public' modifiers on test lifecycle methods.

--- a/sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/ExternalReportFileHandlerTest.java
+++ b/sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/ExternalReportFileHandlerTest.java
@@ -39,1 +39,1 @@ class ExternalReportFileHandlerTest {
-  public void setup() {
+  void setup() {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: php:sonar-php-plugin/src/test/java/org/sonar/plugins/php/PhpPluginTest.java:35

Why is this an issue?

JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be public. Test classes and methods can have any visibility except private. It is however recommended to use the default package visibility to improve readability.

What changed

This hunk removes the 'public' modifier from the setUp() lifecycle method in the JUnit5 test class PhpPluginTest. JUnit5 recommends using default package visibility for test classes, test methods, and lifecycle methods. By changing 'public void setUp()' to 'void setUp()', the code follows JUnit5 conventions and resolves the code smell about unnecessary 'public' modifiers on JUnit5 lifecycle methods.

--- a/sonar-php-plugin/src/test/java/org/sonar/plugins/php/PhpPluginTest.java
+++ b/sonar-php-plugin/src/test/java/org/sonar/plugins/php/PhpPluginTest.java
@@ -35,1 +35,1 @@ class PhpPluginTest {
-  public void setUp() {
+  void setUp() {

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZkoVASCIsbR56mqmhM9 for java:S5786 rule
- AZkoU-_5IsbR56mqmhGg for java:S1130 rule
- AZkoVASeIsbR56mqmhNA for java:S5786 rule
- AZkoVAR0IsbR56mqmhM8 for java:S5786 rule
- AZkoVASSIsbR56mqmhM_ for java:S5786 rule

Generated by SonarQube Agent (task: f1414618-3b8e-4d49-ba83-d56de847243b)
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title fix: resolve 5 SonarQube issues in test files SONARPHP-1817 fix: resolve 5 SonarQube issues in test files May 15, 2026
@hashicorp-vault-sonar-prod
Copy link
Copy Markdown
Contributor

hashicorp-vault-sonar-prod Bot commented May 15, 2026

SONARPHP-1817

@sonar-review-alpha
Copy link
Copy Markdown

sonar-review-alpha Bot commented May 15, 2026

Summary

⚠️ The PR description exceeded the analysis limit and was truncated. The review may not reflect all context.

This PR removes 5 SonarQube code smells from test files:

1 instance of java:S1130 (FileUploadsCheckTest.java:33)

  • Removed unnecessary throws Exception declaration from the lineIssues() test method. The method body doesn't actually throw checked exceptions, so the declaration was misleading.

4 instances of java:S5786 (4 test files)

  • Removed public modifiers from JUnit5 lifecycle methods (@BeforeEach). JUnit5 doesn't require public visibility and best practice is to use package-private visibility for cleaner test code.

All changes are in test files only. No behavior changes—purely stylistic cleanup to align with JUnit5 conventions and improve code readability.

What reviewers should know

Files affected:

  • php-checks/src/test/java/org/sonar/php/checks/phpini/FileUploadsCheckTest.java
  • sonar-php-plugin/src/test/java/org/sonar/plugins/php/PhpPluginTest.java
  • sonar-php-plugin/src/test/java/org/sonar/plugins/php/SymbolScannerTest.java
  • sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/ExternalReportFileHandlerTest.java
  • sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/phpunit/TestFileReportTest.java

Safe to approve:

  • All changes are mechanical test cleanup with zero functional impact
  • Each change addresses a specific SonarQube rule violation
  • No production code is affected
  • Test method behavior is unchanged

Review notes:

  • Verify that lifecycle methods remain properly annotated (@BeforeEach) after removing public
  • Confirm all affected methods are in test classes that use the standard package-private convention

  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ✅

Clean, targeted cleanup — all 5 changes are correct and each fix is well-scoped. The throws IOException kept on SymbolScannerTest.init() is intentional and correct (Files.createTempDirectory is a real checked-exception caller).

One thing worth a follow-up: FileUploadsCheckTest.fileIssue() (line 38, outside the diff) still carries throws Exception even though it calls the same PhpIniCheckTestUtils.check() overload, which handles IOException internally and never propagates a checked exception to callers. Since SonarQube flagged lineIssues() on line 33 for the same pattern, fileIssue() is likely a missed companion fix. It won't cause a test failure, but it leaves the class in an inconsistent state — worth cleaning up in a follow-on commit or as part of this PR.

🗣️ Give feedback

@sonarqube-next
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants